package com.surelution.projects.domain

class UserController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

	def springSecurityService

    def index = {
		
    }
	
	def updatePassword = {
		def oldPassword = params.oldPassword
		def newPassword = params.newPassword
		def confirmPassword = params.confirmPassword
		
		if(newPassword && newPassword.equals(confirmPassword)) {
			def id = springSecurityService.principal.id
			def user = User.get(id)
			println(user)
			println(springSecurityService.encodePassword(oldPassword))
			println(user.password)
			if(springSecurityService.encodePassword(oldPassword).equals(user.password)) {
				user.password = newPassword
				user.save(flush : true)
				redirect(action: "index", controller: "blog")
				return
			}
		}
		
		redirect(action: "index")
	}
}
